/***************************************************************************
 *   Copyright (C) 2009 by Zheng Yonglei
 *   zhengyonglei@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef RECITEGREWORDS_H
#define RECITEGREWORDS_H

#include <iostream>

#include <QMainWindow>
#include <QCheckBox>
#include <QtGui/QWidget>
#include <QTimer>
#include <QTime>
#include <QComboBox>
#include <QShortcut>
#include <QMessageBox>
#include <QToolBar>
#include <QTimeEdit>
#include <QTranslator>
#include <QActionGroup>
#include <QGridLayout>

#include "ui_ReciteGREWords.h"
#include "LoginDialog.h"
#include "BrowseWordsWidget.h"
#include "ReciteWordsWidget.h"
#include "ReciteGREWords.h"
#include "SettingsDialog.h"
#include "SelectListDialog.h"
#include "ReciteAnalysisDialog.h"
#include "MessageBox.h"
#include "SearchDB.h"
#include "ExportDataDialog.h"
#include "ImportDataDialog.h"

using namespace std;

class Language
{
public:
	QString language;
	QAction* action;
	QTranslator* translator;
	bool isValid;
	bool isDefault;

	Language():
		language(QString()),
		action(NULL),
		translator(NULL),
		isValid(false),
		isDefault(false)
	{
	}
};

class ReciteGREWords : public QMainWindow
{
    Q_OBJECT

public:
    ReciteGREWords(QWidget *parent = 0);
    ~ReciteGREWords();

   //void initConnections();

    void readSettings();
	void writeSettings();

	//void loadLanguages();

private:
    Ui::ReciteGREWordsClass ui;

    QAction* mOpenListAct;
    QAction* mOpenAnalysisDialogAct;
    QAction* mResumeAct;
    QAction* mStartAct;
    QAction* mPauseAct;
    QAction* mFinishedCurTaskAct;
    QAction* mSwitchTaskAct;
    QAction* mShowLogApp;
    QAction* mExitApp;
    QAction* mZoomIn;
    QAction* mZoomOut;
    //QAction* mFindWordInDB;
    QAction* mShowLoginDialog;
    QAction* mImportData;
    QAction* mExportData;

    QTimeEdit* mTimeElapsedEditor;
    QTextEdit* mMainBulletin;

    QGridLayout* mCentralGrid;
    BrowseWordsWidget* mBrowseWordsWidget;
    ReciteWordsWidget* mReciteWordsWidget;

    LoginDialog* mLoginDialog;
    SelectListDialog* mSelectListDialog;
    ReciteAnalysisDialog* mReciteAnalysisDialog;
    SettingsDialog* mSettingsDialog;
    ExportDataDialog* mExportDataDialog;
    ImportDataDialog* mImportDataDialog;

    QTimer* mTimer;
    QTime mTime;
    QTimer* mRefreshTimer;
    SearchDB* mSearchDBDialog;

    bool mStartTimer;

   // map<QAction*, Language> mLanguageMap;
   // QActionGroup* mLanguageActionGroup;
    //map<Language, QAction* > mLanguageMap;
   //  mUseEnglish;
	//QAction* mUseChinese;
    //Language mLanguage;
   // QTranslator mChineseTranslator;
    //QVector<Language> mAvailableLanguage;
    //bool mIsPaused;

public slots:
	//general
	void show();
	void resizeEvent(QResizeEvent * event );
	void moveEvent( QMoveEvent * event );
	void recordGeometry();
	//void languageSelected(QAction* action);

	void login();

	//actions
	void openSettingDialog();
	void setProgramFont();
	void openAboutThisProgram();

	//main panel button slots
	void updateTimeElapsedDisplay();
	void updateMainBulletin();
	void openWinLogWidget();
	void openSelectListDialog();
	void openAnalysisDialog();

	void pauseButtonPushed();
	void startButtonPushed();
	void spaceBarPressed();
	void openExportDataDialog();
	void openImportDataDialog();

	void finishCurTask();
	void switchTask();
	void exitApp();
	void resume();
	//void openTools();
	void openLoginDialog();
	void findWordInDB();
	void findWordInDB(QString key);

	//select task dialog button slots
	void reciteTaskSelected();
	void browseTaskSelected();

	//zoom in/out display
	void zoomIn();
	void zoomOut();
};

#endif // RECITEGREWORDS_H
